<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登陆页面</title>
</head>
<body>
    <h2>登录</h2>
    <form id="loginForm">
        <label>用户名<input type="text" name="username" id="username"></label><br>
        <label>密码<input type="password" name="password" id="password"></label><br>
        <button type="submit">登录</button><br>
        <p>没有用户名密码，点击跳转<a href="/register.html">注册页面</a></p>
    </form>
    <script>
        document.getElementById('loginForm').addEventListener('submit',function(event){
            event.preventDefault()
            const username = document.getElementById("username").value;
            const password = document.getElementById("password").value;
            fetch('/login',{
                method:'POST',
                body:new URLSearchParams( {
                    username:username,
                    password:password
                })
            }).then(function(response){
                return response.text()
            }).then(message =>{
                alert(message)
            })
        })
    </script>
</body>
</html>